<template>
  <!-- 访客记录-详情 -->
  <public-modal
    width="500px"
    :title="title"
    modalStyle="visitor-detailModal"
    :publicVisible="publicVisible"
    @handleOk="handleOk"
    @cancel="cancel"
  >
    <div slot="content" style="padding: 20px">
      <div class="search-group" style="width: 100%; padding: 0">
        <div class="input-wrap" style="width: 100%">
          <div class="label">文书名称:</div>
          <div class="input-item" style="width: 100%">
            <a-input :maxLength="30" clearable v-model="queryParam.documentName" placeholder="请输入文书名称" />
          </div>
        </div>

        <div class="input-wrap" style="width: 100%">
          <div class="label">备注信息:</div>
          <div class="input-item" style="width: 100%">
            <a-textarea
              :maxLength="30"
              style="height: 100px; overflow: auto; resize: none"
              v-model="queryParam.memo"
              placeholder="请填写备注信息"
            />
          </div>
        </div>
      </div>
    </div>
  </public-modal>
</template>
<script>
import publicModal from '@/components/publicModal'
import { documentAdd, documentEdit } from '@/api/document'
export default {
  name: 'cancelModel',
  components: { publicModal },
  props: {
    currSelected: {
      type: Object,
      default() {
        return {}
      },
    },
  },
  data() {
    return {
      queryParam: {
        memo: '',
        documentName: '',
      },
      title: '文书模板',
      records: {},
      publicVisible: false,
    }
  },
  mounted() {},
  methods: {
    show(records) {
      this.records = records
      if (records && records.id) {
        this.title = '编辑' + this.title
        this.queryParam = { ...records }
      } else {
        this.title = '新增' + this.title
        this.queryParam.memo = ''
        this.queryParam.documentName = ''
      }
      this.publicVisible = true
    },

    async handleOk() {
      if (this.queryParam.documentName == '') {
        this.$message.error('请填写文书名称')
        return
      }

      if (this.queryParam.memo == '') {
        this.$message.error('请填写备注信息')
        return
      }
      console.log(this.currSelected)
      if (this.title == '新增文书模板') {
        let res = await documentAdd({
          ...this.queryParam,
          industryInformationId: this.currSelected.id,
        })
        this.$message.success(res.message)
        this.publicVisible = false
        this.cancel()
        this.$emit('refresh')
      } else {
        this.queryParam.id = this.records.id
        let res = await documentEdit({
          ...this.queryParam,
          industryInformationId: this.currSelected.id,
        })
        this.$message.success(res.message)
        this.publicVisible = false
        this.cancel()
        this.$emit('refresh')
      }
    },
    cancel() {
      this.publicVisible = false
      this.title = '文书模板'
      this.queryParam = {
        memo: '',
        documentName: '',
      }
    },
  },
}
</script>
